home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 575 / fpupatch / fpu_test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-24  |  6.4 KB  |  256 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <tos.h>
  6.  
  7. #define COUNT    10000L
  8.  
  9.  
  10.  
  11. long time(void)
  12. {
  13.     long    *_hz_200 = (long *) 0x4BA;
  14.     
  15.     return(*_hz_200);
  16. }
  17.  
  18.  
  19.  
  20. double null(double dummy)
  21. {
  22.     return(dummy);
  23. }
  24.  
  25.  
  26.  
  27. main(int argc, char *argv[])
  28. {
  29.     register long    f, i, count;
  30.     register long    time1, time2, leer;
  31.     long            firstTime, lastTime;
  32.     int             mode, error, last, new;
  33.     double          v1, v2, v3, v4, v5, points;
  34.     double            res0, res1, a = M_1_SQRTPI;
  35.     float            flt0, flt1, b = M_1_SQRTPI;
  36.     double          (*fktpntr)(double);
  37.     char           *fktname;
  38.     struct _FKT
  39.     {
  40.         char    *name;
  41.         double    (*pntr)(double);
  42.     } fktarray[] =
  43.     {
  44.         " SQRT  (%6ld) : ", sqrt,
  45.         " EXP   (%6ld) : ", exp,
  46.         " LOG   (%6ld) : ", log,
  47.         " TAN   (%6ld) : ", tan,
  48.         " SIN   (%6ld) : ", sin,
  49.         " COS   (%6ld) : ", cos,
  50.         " ATAN  (%6ld) : ", atan,
  51.         " ASIN  (%6ld) : ", asin,
  52.         " ACOS  (%6ld) : ", acos,
  53.         " TANH  (%6ld) : ", tanh,
  54.         " SINH  (%6ld) : ", sinh,
  55.         " COSH  (%6ld) : ", cosh,
  56.         " ATANH (%6ld) : ", atanh,
  57.         " ASINH (%6ld) : ", asinh,
  58.         " ACOSH (%6ld) : ", acosh,
  59.         NULL               , NULL
  60.     };
  61.  
  62.  
  63.     
  64.     puts("\033E   \033p============================ COPROZESSOR TEST ============================\033q");
  65.     
  66.     if (argc == 1)
  67.     {
  68.         puts ("\n\n  Using: FPU_TEST <counts>");
  69.         puts ("\n\n                                 \033pPress [RETURN]\033q");
  70.         getchar();
  71.         exit(1);
  72.     }
  73.     if (!fpumode(0))
  74.     puts("   \033p============== NO COPROZESSOR OR  _FPU COCKIE NOT INSTALLED ==============\033q\n");
  75.     else
  76.     {
  77.         extern short    _fpuco;
  78.         short            co = _fpuco;
  79.         
  80.         switch (co)
  81.         {
  82.             case 1:
  83.                 puts("   \033p=========================== SFP004 COPROZESSOR ===========================\033q\n");
  84.                 break;
  85.             case 2:
  86.                 puts("   \033p====================== REAL COPROZESSOR (MC68881/2) ======================\033q\n");
  87.                 break;
  88.             case 4:
  89.                 puts("   \033p==================== REAL COPROZESSOR (MC68881)  sure ====================\033q\n");
  90.                 break;
  91.             case 6:
  92.                 puts("   \033p==================== REAL COPROZESSOR (MC68882)  sure ====================\033q\n");
  93.                 break;
  94.             case 8:
  95.                 puts("   \033p=================== MC68040  WITH INTERNAL COPROZESSOR ===================\033q\n");
  96.                 break;
  97.             default:
  98.                 puts("   \033p===================== A COMBINATION  OF COPROZESSORS =====================\033q\n");
  99.         }
  100.     }
  101.     puts(" FUNCTION(ITER) :  WITHOUT COPROZESSOR  |       WITH COPROZESSOR  | ?? |   %");
  102.     puts(" ---------------:-----------------------+-------------------------+----+-------");
  103.     
  104.  
  105.  
  106.     count = COUNT;
  107.     mode = 1;
  108.     if (argc == 2 && (count = atol(argv[1])) == 0)
  109.         count = COUNT;
  110.     if (count < 100)
  111.         count = 100;
  112.     if (count > 999999L)
  113.         count = 999999L;
  114.     
  115.     if (argc == 3)
  116.     {
  117.         if ((count = atol(argv[1])) == 0)
  118.             count = COUNT;
  119.         mode = atoi(argv[2]) & 0x01;
  120.     }
  121.     
  122.  
  123.  
  124.  
  125.     fpumode(1);
  126.     error = 0;
  127.     printf(" check (%6ld) :", count);
  128.     points = (double) count / (double)strlen("-----------------------+-------------------------");
  129.     last = 0;
  130.     for (i = 1; i <= count; i++)
  131.     {
  132.         new = (int)((double)i / points);
  133.         if (new != last)
  134.         {
  135.             for (f = 0; f < new - last; f++)
  136.                 putchar('.');
  137.             last = new;
  138.         }
  139.         v1 = (double)rand() / (double)rand();
  140.         v2 = (double)rand() / (double)rand();
  141.         v3 = (double)rand() / (double)rand();
  142.         v4 = (double)rand() / (double)rand();
  143.         v5 = (double)rand() / (double)rand();
  144.         fpumode(1);
  145.         res0 = v1 * v2 + v3 / v4 + v5;
  146.         fpumode(0);
  147.         res1 = v1 * v2 + v3 / v4 + v5;
  148.         fpumode(mode);
  149.         if (fabs(res1 - res0) > 1E-11)
  150.             error = 1;
  151.     }
  152.     if (!error)
  153.         printf("|\033p OK \033q|\n");
  154.     else
  155.         printf("|\033pERR \033q|\n");
  156.     
  157.     
  158.     
  159.     time1 = Supexec(time);
  160.     for(i = count; i; i--)
  161.         res0 = a;
  162.     time2 = Supexec(time);
  163.     leer = time2 - time1;
  164.     
  165.     printf(" +-*/ X(%6ld) : ", count);
  166.     fpumode(1);
  167.     time1 = Supexec(time);
  168.     for(i = count; i; i--)
  169.         res0 = (a * a - a) / a + a;
  170.     time2 = Supexec(time);
  171.     firstTime = (time2-time1-leer)/4;
  172.     printf("%10ld (%6.3fs)  |   ", firstTime, firstTime / 200.0);
  173.     fpumode(0);
  174.     time1 = Supexec(time);
  175.     for(i = count; i; i--)
  176.         res1 = (a * a - a) / a + a;
  177.     time2 = Supexec(time);
  178.     fpumode(mode);
  179.     lastTime = (time2-time1-leer)/4;
  180.     printf("%10ld (%6.3fs)", lastTime, lastTime / 200.0);
  181.     if (fabs(res1 - res0) < 1E-11)
  182.         printf("  |\033p OK \033q| %6.2f\n", 100.0 * lastTime / firstTime);
  183.     else
  184.         printf("  |\033pERR \033q| %6.2f\n", 100.0 * lastTime / firstTime);
  185.     
  186.     printf(" +-*/ S(%6ld) : ", count);
  187.     fpumode(1);
  188.     time1 = Supexec(time);
  189.     for(i = count; i; i--)
  190.         flt0 = (b * b - b) / b + b;
  191.     time2 = Supexec(time);
  192.     firstTime = (time2-time1-leer)/4;
  193.     printf("%10ld (%6.3fs)  |   ", firstTime, firstTime / 200.0);
  194.     fpumode(0);
  195.     time1 = Supexec(time);
  196.     for(i = count; i; i--)
  197.         flt1 = (b * b - b) / b + b;
  198.     time2 = Supexec(time);
  199.     fpumode(mode);
  200.     lastTime = (time2-time1-leer)/4;
  201.     printf("%10ld (%6.3fs)", lastTime, lastTime / 200.0);
  202.     if (fabs(flt1 - flt0) < 1E-6)
  203.         printf("  |\033p OK \033q| %6.2f\n", 100.0 * lastTime / firstTime);
  204.     else
  205.         printf("  |\033pERR \033q| %6.2f\n", 100.0 * lastTime / firstTime);
  206.     
  207.     
  208.     
  209.     fktpntr = null;
  210.     time1 = Supexec(time);
  211.     for(i = count; i; i--)
  212.         (*fktpntr)(M_1_SQRTPI);
  213.     time2 = Supexec(time);
  214.     leer = time2 - time1;
  215.  
  216.     
  217.     for(f = 0, fktname = fktarray[f].name, fktpntr = fktarray[f].pntr;
  218.         fktname != NULL && fktpntr != NULL;
  219.         f++, fktname = fktarray[f].name, fktpntr = fktarray[f].pntr)
  220.     {
  221.         a = M_1_SQRTPI;
  222.         if (fktpntr == sqrt)
  223.             a = 1234.56789 * M_E;
  224.         if (fktpntr == acosh)
  225.             a = M_2_SQRTPI;
  226.         printf(fktname, count);
  227.         fpumode(1);
  228.         time1 = Supexec(time);
  229.         for(i = count; i; i--)
  230.             (*fktpntr)(a);
  231.         time2 = Supexec(time);
  232.         res0 = (*fktpntr)(a);
  233.         firstTime = (time2-time1-leer)/4;
  234.         printf("%10ld (%6.3fs)  |   ", firstTime, firstTime / 200.0);
  235.         fpumode(0);
  236.         time1 = Supexec(time);
  237.         for(i = count; i; i--)
  238.             (*fktpntr)(a);
  239.         time2 = Supexec(time);
  240.         res1 = (*fktpntr)(a);
  241.         fpumode(mode);
  242.         lastTime = (time2-time1-leer)/4;
  243.         printf("%10ld (%6.3fs)", lastTime, lastTime / 200.0);
  244.         if (fabs(res1 - res0) < 1E-11)
  245.             printf("  |\033p OK \033q| %6.2f\n", 100.0 * lastTime / firstTime);
  246.         else
  247.             printf("  |\033pERR \033q| %6.2f\n", 100.0 * lastTime / firstTime);
  248.     }
  249.  
  250.  
  251.  
  252.     fprintf(stderr, "\n                                 \033pPress [RETURN]\033q");
  253.     getchar();
  254.     return(0);
  255. }
  256.